import request from '@/utils/request'

export default {
  namespaced: true, // 先开启命名空间
  state: {
    list: [], // 新闻列表
  },
  mutations: {
    updateList(state, list) {
      state.list = list
    },
  },
  actions: {
    // timestamp = Date.now() 是 ES6 的默认值语法
    getList(ctx, timestamp = Date.now()) {
      // console.log(ctx, 'ctx')
      // console.log(this, 'this') // 永远指向根 store
      request({
        method: 'GET',
        url: '/v1_0/articles',
        params: {
          channel_id: this.state.Category.cur,
          timestamp,
        },
      }).then(res => {
        ctx.commit('updateList', res.data.data.results)
      })
    },
  },
  getters: {},
}
